
/*
  解题思路：使用三次逆转法，让数组旋转k次
    1. 整体逆置
    2. 逆转子数组[0, k - 1]
    3. 逆转子数组[k, size - 1]
*/
public class Solution2 {
    void rotate(int[] nums, int left, int right){
        while(left < right){
            int temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;
            left++;
            right--;
        }
    }
    public void rotate(int[] nums, int k) {
        k %= nums.length;
        rotate(nums, 0, nums.length-1);
        rotate(nums, 0, k-1);
        rotate(nums, k, nums.length-1);
    }
}


